Previous | Index | Next |

Input stream Iterator

The InputStreamIterator api reads (using the reader function object) successive elements from the input stream for which it was constructed. After it is constructed, and every time next() is used, the iterator reads and stores a value. If the end of the stream is reached (the stream throws a EOFException), the iterator becomes equal to the iterator end-of-stream iterator value. The constructor with no arguments always contructs an end of stream iterator object which is the only legitimate iterator to be used for the end condition. It is impossible to store things into a InputStreamIterator. The main peculiarity of the InputStreamIterator is the fact that the next() method is not equality preservings, that is i.cmp(j) does not guarantee at all that i.next(); j.next(); i.cmp(j). Every time next() is used a new value is returned.

The practical consequence of this fact is that InputStreamIterators can be used only for one-pass algorithms, which actually makes perfect sense, since for multi-pass algorithms it is always more appropriate to use inmemory data structures. Two end-of-stream iterators are always equal. An end-of-stream iterator is not equal to a non-end-of-stream iterator.


Previous | Index | Next |